<%@ include file="/common/taglibs.jsp" %>
<c:set var="createAccountUrl"><spring:url value="maintainAccount.html">
	<spring:param name="action" value="create"/>
	<spring:param name="previousPath" value="${previousPath}"/>
	</spring:url></c:set>


<head>
	<title><spring:message code="accounts.listAccounts.header"/></title>
	<script type="text/javascript">
	var role = "${param.role}";
	var idvOrOrg = "${param.idvOrOrg}";
	$(document).ready(function(){
		if(role.length > 0){
			var roleEl = $("#role option[value=" + role + "]");
			roleEl.attr("selected", "selected");
		}

		if(idvOrOrg.length > 0){
			var idvOrOrgEl = $("#idvOrOrg option[value=" + idvOrOrg + "]");
			idvOrOrgEl.attr("selected", "selected");
		}

		$("#addNewAccount").click(function(){
			location.assign("${createAccountUrl}");
		});
	});
	</script>
</head>
<p>
	<spring:message code="accounts.listAccounts.header"/>
</p>
<table>
	<tr>
		<td>
		<form action="listAccounts.html" method="get">
		<table>
			<tr>
				<td><label for="accountName"><spring:message code="accounts.listAccounts.accountName"/></label></td>
				<td><input type="text" name="accountName" id="accountName" value="${param.accountName}"/></td>
			</tr>
			<tr>
				<td><label for="role"><spring:message code="accounts.listAccounts.role"/></label></td>
				<td><select name="role" id="role">
				  <option value=""></option>
				  <option value="Administrator">Administrator</option>
				  <option value="Clerk">Clerk</option>
				  <option value="Customer">Customer</option>
				  <option value="Publisher">Publisher</option>
				  <option value="Carrier">Carrier</option>
				</select></td>
			</tr>
			<tr>
				<td><label for="idvOrOrg"><spring:message code="accounts.listAccounts.IndividualOrOrganization"/></label></td>
				<td><select name="idvOrOrg" id="idvOrOrg">
				  <option value=""></option>
				  <option value="IndividualAccount">Individual</option>
				  <option value="OrganizationAccount">Organization</option>
				</select></td>
			</tr>
			<tr>
				<td colspan="2" style="text-align: right;">
					<button type="submit" class="aButton" style="margin-right: 10px;"><spring:message code="accounts.listAccounts.submit"/></button>
					<button type="reset" class="aButton" style="margin-right: 10px;"><spring:message code="accounts.listAccounts.reset"/></button>
				</td>
			</tr>
		</table>
		</form>
		</td>
	</tr>
	<tr>
		<td>
		<display:table name="accounts" cellspacing="0" cellpadding="0" requestURI="" 
		   	defaultsort="1" id="account" pagesize="25" class="table" export="true">
		   	
		    <display:column sortable="true" titleKey="accounts.listAccounts.id" >
		    	<a href="<spring:url value='maintainAccount.html'>
		    		<spring:param name="accountId" value="${account.id}" />
		    		<spring:param name="action" value="update" />
		    		<spring:param name="previousPath" value="${previousPath}" />
		    		</spring:url>">${account.id}</a>
		    </display:column>
		    	
		    <display:column sortable="true" titleKey="accounts.listAccounts.accountName">
		    	${account.accountName}
		    </display:column>
		    
		    <display:column sortable="true" titleKey="accounts.listAccounts.IndividualOrOrganization">
		    	<spring:message code="${sf:getUserAccountTypeMessageCode(account)}"/>
		    </display:column>
		    
		    <display:column sortable="true" titleKey="accounts.listAccounts.rolesName">
		    	<c:forEach var="role" items="${account.roles}" varStatus="roleStatus">
		    		<c:choose>
		    			<c:when test="${roleStatus.first}">${role.class.simpleName}</c:when>
		    			<c:otherwise>, ${role.class.simpleName}</c:otherwise>
		    		</c:choose>
		    	</c:forEach>
		    </display:column>
		    
		    <display:column sortable="true" titleKey="accounts.listAccounts.enabled">
		    	<c:choose>
		    		<c:when test="${account.enabled}">
		    			<spring:message code="accounts.listAccounts.enabled.true"/>
		    		</c:when>
		    		<c:when test="${account.enabled == false}">
		    		<spring:message code="accounts.listAccounts.enabled.false"/>
		    		</c:when>
		    	</c:choose>
		    </display:column>
		    
		    <display:setProperty name="paging.banner.item_name">
		    	<spring:message code="accounts.listAccounts.item"/>
		    </display:setProperty>
		    <display:setProperty name="paging.banner.items_name">
		    	<spring:message code="accounts.listAccounts.items"/>
		    </display:setProperty>
		
		    <display:setProperty name="export.excel.filename" value="UserAccounts.xls"/>
		    <display:setProperty name="export.csv.filename" value="UserAccounts.csv"/>
		    <display:setProperty name="export.pdf.filename" value="UserAccounts.pdf"/>
		</display:table>
		</td>
	</tr>
	<tr>
		<td style="text-align: right;"><button id="addNewAccount" class="aButton" style="margin-right: 10px;"><spring:message code="accounts.listAccounts.addNewAccount"/></button></td>
	</tr>
</table>